var util = require('../../utils/util.js');
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var app = getApp();
const imgurl = app.globalData.imgUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Info:[],//获取订单信息,店铺信息,商品信息等
    imgurl: imgurl,
    order_id:'',
    cont:"",
    anonymous:0,
    starList: [
      { path: '/images/star1.png', selected: false },
      { path: '/images/star1.png', selected: false },
      { path: '/images/star1.png', selected: false },
      { path: '/images/star1.png', selected: false },
      { path: '/images/star1.png', selected: false },
    ],
    stars: [0, 1, 2, 3, 4],
    normalSrc: '/images/star1.png',
    selectedSrc: '/images/star2.png',
    halfSrc: '/images/star2.png',
    key: 0,//评分
    userInfo: '',
    radioChecked:false,
  },
  clickStar:function(e){
    var index=e.currentTarget.dataset.index;
    var that=this;
    if(that.data.starList[index].selected){
      that.data.starList[index].path = '/images/star1.png';
      that.data.starList[index].selected=false;
    }else{
      that.data.starList[index].path = '/images/star2.png';
      that.data.starList[index].selected=true;
    }
    that.setData({
      starList: that.data.starList
      });
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orderId = options.orderId;
    var that = this;
    this.getInfo(orderId);
    that.setData({
      userInfo: app.getUserInfo(),
    });
  },
  //获取订单信息,咨询师信息
  getInfo: function (orderId){
    var that = this;
    util.post(app.api.getOrderedById, { orderId: orderId }, function (res) {
      that.setData({
        Info: res.data
      })
    })
  },

  //评论提交表单
  submistEvaTap:function(e){
    var that = this
  
    var anonymous = that.data.anonymous;
    if (anonymous == null) { anonymous = 0; }
    util.post(app.api.createEvaluate, {
      openid: app.globalData.openid,
      nickName: that.data.userInfo.nickName,
      hunterid: that.data.Info.hunterId,
      huntername: that.data.Info.huntername,
      orderId: that.data.Info.id,
      orderdescIds: "￥"+that.data.Info.orderMoney + "/" + that.data.Info.orderdesc,
      buyerEvalContent: that.data.cont,
      buyerEvalScore: that.data.key,
      anonymous: anonymous,
    }, function (res) {
    
        if (res.data != -1) {
          // 保存成功
          wx.showToast({
            title: '感谢您的点评',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function () {
            wx.navigateBack({
              url: '/pages/my-orders/my-orders',
            })
          }, 800);
        } else {
          app.alert("服务器异常");
        }
      // if (data.code == 0) {
      //   wx.navigateTo({
      //     url:'/pages/assess/assess?username='+username
      //   })
      // }
    })
  },
  //点击右边,半颗星
  selectLeft: function (e) {
    var key = e.currentTarget.dataset.key
    // if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
    //   //只有一颗星的时候,再次点击,变为0颗
    //   key = 0;
    // }
 
    this.setData({
      key: key
    })

  },
  //点击左边,整颗星
  selectRight: function (e) {
    var key = e.currentTarget.dataset.key
 
    this.setData({
      key: key
    })
  },
  setCont: function (e) {
    this.setData({
      cont: e.detail.value
    });
  },
 
  radioChange: function (e) {

    var that=this;
    var radioChecked = that.data.radioChecked;
    if (radioChecked){ 
      radioChecked=false;
    }else{
      radioChecked = true;
    }

    that.setData({
      anonymous: e.detail.value, 
      radioChecked: radioChecked
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})